/**
 * A singular factory that contains all of the DateTime-factories needed in the SDV processing.
 */
package org.hackystat.ui.telemetryviewer.server;

import java.text.SimpleDateFormat;
import java.util.Locale;

/**
 * A singular factory that contains all of the DateTime-factories needed in the SDV processing.
 * @author David J Nickles
 * 
 */
public class SimpleDateFactories {
  
  private static SimpleDateFactories singular;
  
  private SimpleDateFormat xmlfactory;
  private SimpleDateFormat zonefactory;
  private SimpleDateFormat headerfactory;
  private SimpleDateFormat bodyfactory;
  private SimpleDateFormat timefactory;
  private SimpleDateFormat datefactory;
  private SimpleDateFormat quantizedfactory;

  /**
   * Construct all the DateTime product lines in this factory.
   */
  private SimpleDateFactories() {
    initDateTimeFactories();
  }
  
  /**
   * This method constructs the DateTimeFactories that will be used to manipulate timestamps.
   */
  private void initDateTimeFactories() {
    Locale locale = Locale.ENGLISH;
    this.xmlfactory = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", locale);
    this.quantizedfactory = new SimpleDateFormat("yyyy-MM-dd'T00:00:00'Z", locale);
    this.zonefactory = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", locale);
    this.headerfactory = new SimpleDateFormat("EEE, MMM dd, h:mma", locale);
    this.bodyfactory = new SimpleDateFormat("EEE, MMM dd, h:mm:ssa", locale);
    this.timefactory = new SimpleDateFormat("h:mm:ssa", locale);
    this.datefactory = new SimpleDateFormat("yyyy-MM-dd", locale);
  }
  
  /**
   * @return a singular reference to a SDVDateTimeFactory that this class maintains.
   */
  public static SimpleDateFactories getInstance() {
    if (singular == null) {
      return (singular = new SimpleDateFactories());
    } 
    else {
      return singular;
    }
  }

  /**
   * @return the datefactory
   */
  public SimpleDateFormat getDatefactory() {
    return datefactory;
  }

  /**
   * @return the bodyfactory
   */
  public SimpleDateFormat getBodyfactory() {
    return bodyfactory;
  }

  /**
   * @return the headerfactory
   */
  public SimpleDateFormat getHeaderfactory() {
    return headerfactory;
  }

  /**
   * @return the timefactory
   */
  public SimpleDateFormat getTimefactory() {
    return timefactory;
  }

  /**
   * @return the xmlfactory
   */
  public SimpleDateFormat getXmlfactory() {
    return xmlfactory;
  }

  /**
   * @return the zonefactory
   */
  public SimpleDateFormat getZonefactory() {
    return zonefactory;
  }

  /**
   * @return the quantizedfactory
   */
  public SimpleDateFormat getQuantizedfactory() {
    return quantizedfactory;
  }
}
